<?php
/* 
 *   if user has selected a custom template, use it.
 *   otherwise default to pfsense tempalte
 */
if($config['theme'] <> "")
	$g['theme'] = $config['theme'];
else
	$g['theme'] = "stairway";

/*
 *  If this device is an apple ipod/iphone
 *  switch the theme to one that works with it.
 */
$apple_ua = array("iPhone","iPod");
foreach($apple_ua as $useragent)
	if(strstr($_SERVER['HTTP_USER_AGENT'], $useragent))
		$g['theme'] = "stairway";

$pagetitle = gentitle( $pgtitle );

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title><?=$pagetitle;?></title>
        <?php if (strpos($_SERVER["SCRIPT_FILENAME"], "wizard.php") !== false &&
                  file_exists("{$g['www_path']}/themes/{$g['theme']}/wizard.css")): ?>
					<?php outputCSSFile("/themes/{$g['theme']}/wizard.css"); ?>
        <?php else: ?>
        	<link rel="stylesheet" href="/themes/<?php echo $g['theme']; ?>/all.css" media="all" />
        <?php endif; ?>
		<?php 
			if(file_exists("{$g['www_path']}/niftycssCode.css")) 
				outputCSSFile("/niftycssCode.css"); 
			if(file_exists("{$g['www_path']}/niftycssprintCode.css")) 
				outputCSSFile("/niftycssprintCode.css");
			if(file_exists("{$g['www_path']}/javascript/niftyjsCode.js")) 
				outputJavaScriptFile("/javascript/niftyjsCode.js"); 
		?>
		<script type="text/javascript">
			var theme = "<?php echo $g['theme']; ?>";
		</script>
		<?php outputJavaScriptFile("/themes/{$g['theme']}/loader.js"); ?>
<?php
		if($_GET['enablefirebuglite']) {
			outputJavaScriptFile("/javascript/pi.js");
			outputJavaScriptFile("/javascript/firebug-lite.js");
		}
		outputJavaScriptFile("/javascript/scriptaculous/prototype.js");
		outputJavaScriptFile("/javascript/scriptaculous/scriptaculous.js");
		outputJavaScriptFile("/javascript/scriptaculous/effects.js");
		outputJavaScriptFile("/javascript/scriptaculous/dragdrop.js");
		if(file_exists("{$g['www_path']}/javascript/global.js"))
			outputJavaScriptFile("/javascript/global.js");

	/*
	 *	Find all javascript files that need to be included
	 *	for this page ... from the arrays ... :)
	 *	Coded by: Erik Kristensen
	 */

	$dir  = trim(basename($_SERVER["SCRIPT_FILENAME"]), '.php');
	$path = "{$g['www_path']}/javascript/" . $dir . "/";
	if (is_dir($path)) {
		if ($dh = opendir($path)) {
			while (($file = readdir($dh)) !== false) {
		   		if (is_dir($file)) continue;
				//echo "\t".'<script type="text/javascript" src="/javascript/'.$dir.'/'.$file.'"></script>'."\n";
				outputJavaScriptFile("/javascript/{$dir}/{$file}"); 
			}
			closedir($dh);
		}
	}

if (!isset($closehead))
	echo "</head>";
?>
